<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\IntegralRecords
 *
 * @property int $id
 * @property int|null $uid
 * @property float|null $integral
 * @property string|null $body
 * @property string|null $from
 * @property int|null $type
 * @property int|null $created_at
 * @property-read \App\Models\User|null $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereBody($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereFrom($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereIntegral($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IntegralRecords whereUid($value)
 * @mixin \Eloquent
 */
class IntegralRecords extends Model
{
    protected $table = 'integral_records';
    protected $primaryKey = 'id';
    protected $guarded    = ['id'];

    public $timestamps = false;

    static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub

        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }
}
